#pragma once
#include "BRTree.h"

namespace MyMap {
	template <class K, class T>
	class map {
		struct SetKeyOfT {
			const K& operator()(const pair<K, T>& data) {
				return data.first;
			}
		};
		typedef BRTree<K, pair<const K, T>, SetKeyOfT> tree;
	public:
		typedef typename BRTree<K, pair<const K, T>, SetKeyOfT>::iterator iterator;
		typedef typename BRTree<K, pair<const K, T>, SetKeyOfT>::const_iterator const_iterator;

		T& operator[](const pair<K, T>& e) {
			iterator ret = _t.insert(e).first;
			return ret->second;
		}

		iterator begin() {
			return _t.begin();
		}

		iterator end() {
			return _t.end();
		}

		const_iterator begin() const {
			return _t.begin();
		}

		const_iterator end() const {
			return _t.end();
		}

		pair<iterator, bool> insert(const pair<K, T>& kv) {
			return _t.insert(kv);
		}

	private:
		tree _t;
	};
}
